# -- coding: utf-8 --
from tools.Request_General import BaseAPI


class MysqlDataTable(BaseAPI):
    """数据表组件for mysql"""

    def save_edit_datatable(self, payload):
        """数据表新建&编辑（前端调用）"""
        r = self.request_send(json=payload)
        return r

    def save_datatable(self, payload):
        """数据表新建&编辑（后端调用）"""
        r = self.request_send(json=payload)
        return r

    def delete_datatable(self, payload):
        """只删除物理表"""
        r = self.request_send(json=payload)
        return r

    def generateActualTableName(self, payload):
        """根据tableName生成实际物理表名"""
        r = self.request_send(json=payload)
        return r

    def get_using_view_data(self, payload):
        """数据表使用视图获取数据"""
        r = self.request_send(json=payload)
        return r

    def customize_sql(self, payload):
        """数据表使用视图-自定义sql查询"""
        r = self.request_send(json=payload)
        return r

    def get_actual_tablename(self, payload):
        """获取数据表实际表名"""
        r = self.request_send(json=payload)
        return r

    def get_datatable_column_list(self, payload):
        """根据实际表名，查询数据表字段信息"""
        r = self.request_send(params=payload)
        return r

    def get_datatable_columnInfo(self, payload):
        """根据列名获取数据表的Column信息"""
        r = self.request_send(json=payload)
        return r

    def custom_sql_execute(self, payload):
        """自定义SQL执行(后端调用)--增删改查，支持多表联合查询"""
        r = self.request_send(json=payload)
        return r

    def data_diff(self, payload):
        """判断数据表组件元素配置信息和实际物理数据表字段信息是否一致"""
        r = self.request_send(json=payload)
        return r

    def delete_data(self, payload):
        """删除数据表的数据"""
        r = self.request_send(json=payload)
        return r

    def distinct_column_members(self, payload):
        """查询数据表成员个数"""
        r = self.request_send(json=payload)
        return r

    def get_data_execute_sql(self, payload):
        """执行查询sql查询数据表的数据"""
        r = self.request_send(json=payload)
        return r

    def insert_data(self, payload):
        """向数据表中写入数据"""
        r = self.request_send(json=payload)
        return r

    def table_ifexists(self, payload):
        """根据数据表名称判断数据表是否存在"""
        r = self.request_send(json=payload)
        return r

    def table_ifexists_physical(self, payload):
        """只判断物理数据表是否存在"""
        r = self.request_send(json=payload)
        return r

    def table_info_field(self, payload):
        """获取数据表元素信息（从平台获取信息)"""
        r = self.request_send(json=payload)
        return r

    def table_info_field_physical(self, payload):
        """获取数据表元素信息（从物理表获取信息）"""
        r = self.request_send(json=payload)
        return r

    def update_data(self, payload):
        """更新数据表中的数据"""
        r = self.request_send(json=payload)
        return r

    def only_check(self, payload):
        """数据表保存、编辑前的仅校验接口（后端组件调用）"""
        r = self.request_send(json=payload)
        return r

    def only_save(self, payload):
        """数据表编辑--仅保存（后端组件调用，新建时实际表名的末尾加随机数）"""
        r = self.request_send(json=payload)
        return r

    def batch_actual_tablename(self, payload):
        """根据元素名称批量获取实际表名"""
        r = self.request_send(json=payload)
        return r

    def batch_custom_sql(self, payload):
        """批量自定义SQL执行(后端调用)--增删改查，支持多表联合查询"""
        r = self.request_send(json=payload)
        return r

    def batch_datatable_info(self, payload):
        """批量获取数据表信息"""
        r = self.request_send(json=payload)
        return r

    def physical_table_exist(self, payload):
        """根据元素信息或者直接通过传参的实际表名，判断对应的物理数据表是否存在"""
        r = self.request_send(json=payload)
        return r

    def export_table_element(self, payload):
        """元素导出"""
        r = self.request_send(params=payload)
        return r

    def copy_table_element(self, payload):
        """元素复制(单条复制)"""
        r = self.request_send(json=payload)
        return r

    def import_table_element(self, payload):
        """元素导入"""
        r = self.request_send(json=payload)
        return r

    def batch_select(self, payload):
        """批量的自定义select查询接口（支持多表联合join）"""
        r = self.request_send(json=payload)
        return r


if __name__ == '__main__':
    pass
    # from application.general_create import COOKIE, APP_ID, SPACE_ID
    # headers = {"cookie": COOKIE, "language": "zh-cn", "app": APP_ID, "space": SPACE_ID}
    # print(headers)
    # r = MysqlDataTable(version="1.0", headers=headers).physical_table_exist({'actualTableName': '3221','elementBaseInfo': {'elementName': 'account_tc', 'folderId': 'DIR22e7131697cc', 'path': ''}})
    # print(r.text)
